package com.springmvc.controller;

import com.springmvc.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * 将后台数据传递给前端
 */
@Controller
@RequestMapping("/mv")
public class ModelAndViewController {

    @RequestMapping("/home")
    public ModelAndView home(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("home");//视图名称
        mv.addObject("userName","张三");//给页面传递参数

        mv.addObject("user",new User(1L,"李四","123456",22D));

        return mv;//返回视图
    }

    @RequestMapping("/forward_home1")
    public String forward_home1(){
        return "forward:/WEB-INF/jsp/home.jsp";
    }

    @RequestMapping("/forward_home2")
    public String forward_home2(){
        return "home";
    }

    /**
     * 重定向:
     *  redirect:/xxx/xx/xxx
     *  再次发起一个请求,原来带的参数 都没有了
     *
     * @return
     */
    @RequestMapping("/test_redirect")
    public String test_redirect(){
        return "redirect:/login";
    }

}
